package com.boang.ch;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/*
  @author: 13813
  @date: 2024/12/12 10:28
*/
public class FileWriterDemo {
    public static void main(String[] args) throws IOException {
//        write();
        //读
//        read();
//        readWhile();
        //复制粘贴

        FileReader fileReader = new FileReader("fw.txt");
        FileWriter fileWriter = new FileWriter("fw2.txt", true);
        int i;
        while (  ( i = fileReader.read() ) != -1 ){
            fileWriter.write(i);
        }
        fileWriter.close();
        fileReader.close();
    }

    private static void readWhile() throws IOException {
        FileReader fileReader = new FileReader("fw.txt");
        int i;
        while (  ( i = fileReader.read() ) != -1 ){
            System.out.println((char)i);
        }
        fileReader.close();
    }

    private static void read() throws IOException {
        FileReader fileReader = new FileReader("fw.txt");
        int i = fileReader.read();
        System.out.println(i);

        int i2 = fileReader.read();
        System.out.println(i2);

        int i3 = fileReader.read();
        System.out.println(i3);

        int i4 = fileReader.read();
        System.out.println(i4);

        fileReader.close();
    }

    private static void write() throws IOException {
        FileWriter fileWriter = new FileWriter("fw.txt", true);
        fileWriter.write("a");
        fileWriter.write("b");
        fileWriter.write("c");
        fileWriter.close();
    }
}
